package cn.gotom.svg;

import android.graphics.Matrix;
import android.graphics.RectF;
import cn.gotom.svg.xml.StyleAttribute;

/**
 * @author 裴绍国
 * @author <a href="mailto:peixere@gmail.com">裴绍国</a>
 */
public class TransformableElement extends SVGElement
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	protected Matrix xform = null;

	/** Creates a new instance of BoundedElement */
	public TransformableElement()
	{
	}

	public TransformableElement(String id, SVGElement parent)
	{
		super(id, parent);
	}

	/**
	 * Fetches a copy of the cached AffineTransform. Note that this value will only be valid after the node has been updated.
	 * 
	 * @return
	 */
	public Matrix getXForm()
	{
		return new Matrix(xform);
	}

	protected void build() throws SVGException
	{
		super.build();

		StyleAttribute attr = new StyleAttribute();
		if (getAttribute(attr.setName(StyleAttribute.Transform)))
		{
			xform = parseTransform(attr.getStringValue());
		}
	}

	protected RectF boundsToParent(RectF rect)
	{
		if (xform == null)
			return rect;
		xform.mapRect(rect);
		return rect;
	}

	@Override
	public boolean updateTime(double curTime) throws SVGException
	{
		// TODO Auto-generated method stub
		return false;
	}
}
